package cn.tianyun.pethome.login.controller;

import cn.tianyun.pethome.basic.exception.BusinessException;
import cn.tianyun.pethome.basic.util.AjaxResult;
import cn.tianyun.pethome.login.domain.LoginVo;
import cn.tianyun.pethome.org.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILogininfoService logininfoService;
    @PostMapping
    public AjaxResult login(@RequestBody LoginVo loginVo){
        try {
            AjaxResult ajaxResult = logininfoService.jwtLogin(loginVo);
            return ajaxResult;
        }catch (BusinessException e){
            return AjaxResult.creat().setSuccess(false).setMsg(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.creat().setSuccess(false).setMsg("网络故障");
        }
    }
}
